package com.source.baseData.controller;

import com.source.barcodeMachineStatus.entity.BarcodeMachineStatus;
import com.source.barcodeMachineStatus.service.BarcodeMachineStatusService;
import com.source.utils.CommonResult;
import com.source.utils.ResultEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author IceBerg777
 * @since 2021-04-10
 */

@Api(tags = "主页面的图表")
@RestController
@RequestMapping("/main-chart")
@CrossOrigin
public class MainChartController {

    @Autowired
    private BarcodeMachineStatusService barcodeMachineStatusService;

    @ApiOperation(value = "图表 - 返回Map集合，key是状态（卡纸、正常、离线等），value是List集合")
    @GetMapping("/findStatusChart")
    public CommonResult<Map<String, Object>> findListByHouseId(){
        Map<String, Object> map = barcodeMachineStatusService.findStatusChart();
        return new CommonResult<Map<String, Object>>(ResultEnum.SUCCESS, map);
    }

    @ApiOperation(value = "图表 - 根据屠宰场id，返回Map集合，key是状态（卡纸、正常、离线等），value是List集合")
    @GetMapping("/findStatusChartByHouseId")
    public CommonResult<Map<String, Object>> findListByHouseId(@RequestParam(value = "houseId", required = false) String houseId){
        if(null == houseId){
            return findListByHouseId();
        }
        Map<String, Object> map = barcodeMachineStatusService.findStatusChart(houseId);
        return new CommonResult<Map<String, Object>>(ResultEnum.SUCCESS, map);
    }

    @ApiOperation(value = "图表 - 根据状态查询list集合")
    @GetMapping("/findListByStatus/{status}")
    public CommonResult<List<BarcodeMachineStatus>> findListByStatus(@PathVariable String status){

        List<BarcodeMachineStatus> list = barcodeMachineStatusService.findListByStatus(status);
        return new CommonResult<List<BarcodeMachineStatus>>(ResultEnum.SUCCESS, list);
    }
}
